import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class BDMapData {
  BDMapData({
    this.status,
    this.message,
    this.result,
  });

  factory BDMapData.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Result> result = jsonRes['result'] is List ? <Result>[] : null;
    if (result != null) {
      for (final dynamic item in jsonRes['result']) {
        if (item != null) {
          result.add(Result.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return BDMapData(
      status: asT<int>(jsonRes['status']),
      message: asT<String>(jsonRes['message']),
      result: result,
    );
  }

  int status;
  String message;
  List<Result> result;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'status': status,
        'message': message,
        'result': result,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class Result {
  Result({
    this.name,
    this.location,
    this.uid,
    this.province,
    this.city,
    this.district,
    this.business,
    this.cityid,
    this.tag,
    this.address,
    this.children,
    this.adcode,
  });

  factory Result.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Children> children = jsonRes['children'] is List ? <Children>[] : null;
    if (children != null) {
      for (final dynamic item in jsonRes['children']) {
        if (item != null) {
          children.add(Children.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return Result(
      name: asT<String>(jsonRes['name']),
      location: Location.fromJson(asT<Map<String, dynamic>>(jsonRes['location'])),
      uid: asT<String>(jsonRes['uid']),
      province: asT<String>(jsonRes['province']),
      city: asT<String>(jsonRes['city']),
      district: asT<String>(jsonRes['district']),
      business: asT<String>(jsonRes['business']),
      cityid: asT<String>(jsonRes['cityid']),
      tag: asT<String>(jsonRes['tag']),
      address: asT<String>(jsonRes['address']),
      children: children,
      adcode: asT<String>(jsonRes['adcode']),
    );
  }

  bool beyond;
  String name;
  Location location;
  String uid;
  String province;
  String city;
  String district;
  String business;
  String cityid;
  String tag;
  String address;
  List<Children> children;
  String adcode;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'name': name,
        'location': location,
        'uid': uid,
        'province': province,
        'city': city,
        'district': district,
        'business': business,
        'cityid': cityid,
        'tag': tag,
        'address': address,
        'children': children,
        'adcode': adcode,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class Location {
  Location({
    this.lat,
    this.lng,
  });

  factory Location.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Location(
          lat: asT<double>(jsonRes['lat']),
          lng: asT<double>(jsonRes['lng']),
        );

  double lat;
  double lng;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'lat': lat,
        'lng': lng,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class Children {
  Children({
    this.uid,
    this.name,
    this.show_name,
  });

  factory Children.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Children(
          uid: asT<String>(jsonRes['uid']),
          name: asT<String>(jsonRes['name']),
          show_name: asT<String>(jsonRes['show_name']),
        );

  String uid;
  String name;
  String show_name;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'uid': uid,
        'name': name,
        'show_name': show_name,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
